Skip to content

feat: adopt new HTTP layer from OpenAPIRuntime and migrate Functions to it #766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

grdsdev
Copy link
Collaborator

@grdsdev grdsdev commented Aug 4, 2025

What kind of change does this PR introduce?

This PR introduces a major architectural change by adopting the OpenAPIRuntime HTTP layer and migrating the Functions client to use it. This addresses issue #634.

What is the current behavior?

  • Functions client uses a custom fetch-based HTTP implementation
  • HTTP layer lacks standardization and modern Swift HTTP patterns
  • Limited middleware and transport abstraction capabilities
  • No consistent auth transport handling across clients

What is the new behavior?

Core HTTP Layer (Sources/Helpers/HTTP/)

  • New HTTP Client: Introduced a standardized Client struct using OpenAPIRuntime's ClientTransport protocol
  • Transport Abstraction: Clean separation between HTTP transport and business logic
  • Middleware Support: Built-in middleware chain for request/response interception
  • Auth Transport: New AuthClientTransport for automatic Bearer token injection

Functions Client Migration

  • Modernized Architecture: Migrated FunctionsClient from fetch-based to OpenAPIRuntime transport
  • Backwards Compatibility: Added FetchTransportAdapter to maintain compatibility with existing fetch handlers
  • Shared Components: Moved FetchTransportAdapter to Helpers module for reuse across other client migrations
  • Cleaner API: Simplified internal HTTP handling while maintaining public API compatibility
  • Better Error Handling: Improved error propagation through the transport layer

Dependencies Added

  • swift-openapi-runtime: Core HTTP transport abstractions
  • swift-openapi-urlsession: URLSession-based transport implementation
  • swift-log: Structured logging support
  • swift-collections: Enhanced collection types

Testing & Integration

  • Integration Tests: Added comprehensive FunctionsIntegrationTests with local Supabase setup
  • Mirror Function: Added test Edge Function for integration testing
  • Test Coverage: Maintained existing unit tests while adding integration coverage

Infrastructure

  • CI Optimizations: Added path filtering to optimize CI workflow performance
  • Build Configuration: Updated Package.swift with new dependencies and proper module exports

Key Files Changed

  • Sources/Helpers/HTTP/Client.swift: New standardized HTTP client
  • Sources/Helpers/HTTP/LoggingMiddleware.swift: HTTP request/response logging
  • Sources/Helpers/HTTP/FetchTransportAdapter.swift: Shared adapter for legacy fetch handlers (moved from Functions)
  • Sources/Supabase/AuthClientTransport.swift: Auth-aware transport wrapper
  • Sources/Functions/FunctionsClient.swift: Migrated to new HTTP layer
  • Tests/IntegrationTests/FunctionsIntegrationTests.swift: New integration test suite
  • Package.swift: Added OpenAPIRuntime and supporting dependencies

Benefits

  • Standardization: Consistent HTTP handling across the SDK
  • Extensibility: Easy to add new middleware and transport implementations
  • Performance: Optimized request/response handling
  • Maintainability: Cleaner separation of concerns
  • Future-Proof: Built on Apple's official OpenAPI standards

This change lays the foundation for migrating other clients (Auth, Storage, PostgREST, etc.) to the same standardized HTTP layer.

@grdsdev grdsdev changed the title chore: HTTP layer from OpenAPIRuntime refactor: adopt new HTTP layer from OpenAPIRuntime and migration Functions to it Aug 5, 2025
@grdsdev grdsdev changed the title refactor: adopt new HTTP layer from OpenAPIRuntime and migration Functions to it feat: adopt new HTTP layer from OpenAPIRuntime and migration Functions to it Aug 5, 2025
@grdsdev grdsdev changed the title feat: adopt new HTTP layer from OpenAPIRuntime and migration Functions to it feat: adopt new HTTP layer from OpenAPIRuntime and migrate Functions to it Aug 5, 2025
@coveralls
Copy link

coveralls commented Aug 5, 2025

Pull Request Test Coverage Report for Build 16836901907

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 130 of 185 (70.27%) changed or added relevant lines in 5 files are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.4%) to 77.009%

Changes Missing Coverage Covered Lines Changed/Added Lines %
Sources/Supabase/AuthClientTransport.swift 0 7 0.0%
Sources/Helpers/HTTP/Client.swift 34 45 75.56%
Sources/Functions/FunctionsClient.swift 75 92 81.52%
Sources/Helpers/HTTP/LoggingMiddleware.swift 3 23 13.04%
Files with Coverage Reduction New Missed Lines %
Sources/Functions/FunctionsClient.swift 3 87.34%
Totals Coverage Status
Change from base Build 16830846344: -0.4%
Covered Lines: 5557
Relevant Lines: 7216

💛 - Coveralls

@grdsdev grdsdev force-pushed the new-http-layer branch 2 times, most recently from 316e7bc to bfcc4cf Compare August 8, 2025 17:43
- Move FetchTransportAdapter from Functions to Sources/Helpers/HTTP/
- Remove duplicate implementation from FunctionsClient
- Keep package visibility for sharing across modules
- Enables reuse for other module migrations in future PRs

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants